<?php

class learning extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'learning':
	 * @var integer $id
	 * @var integer $class_id
	 * @var integer $pupil_id
	 * @var integer $subject_id
	 * @var string $recommendation
	 * @var string $helpsheets
	 * @var string $discipline
	 * @var string $notes
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'learning';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pupil_id, subject_id', 'required'),
                        array('subject_id','exist',
                                 'on' =>'ajax',
                                'attributeName'=>'sunject_name',
                                'className'=>'Subjects',
                                ),
                        array('pupil_id','exist',
                                 'on' =>'ajax',
                                'attributeName'=>'sunject_name',
                                'className'=>'Subjects',
                                ),
			//array('class_id, pupil_id, subject_id', 'numerical', 'integerOnly'=>true),
			array('recommendation, helpsheets, discipline', 'length', 'max'=>256),
			array('notes', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, class_id, pupil_id, subject_id, recommendation, helpsheets, discipline, notes', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'class_id' => 'Class',
			'pupil_id' => 'שם תלמיד',
			'subject_id' => 'מקצוע',
			'recommendation' => 'המלצה',
			'helpsheets' => 'דפי עזר',
			'discipline' => 'משמעת',
			'notes' => 'הערות נוספות',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('class_id',$this->class_id);

		$criteria->compare('pupil_id',$this->pupil_id);

		$criteria->compare('subject_id',$this->subject_id);

		$criteria->compare('recommendation',$this->recommendation,true);

		$criteria->compare('helpsheets',$this->helpsheets,true);

		$criteria->compare('discipline',$this->discipline,true);

		$criteria->compare('notes',$this->notes,true);

		return new CActiveDataProvider('learning', array(
			'criteria'=>$criteria,
		));
	}
}